package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.CangkuMapper;
import com.zhongyu.pojo.Cangku;
import com.zhongyu.pojo.Goods;
import com.zhongyu.service.CangKuService;
import com.zhongyu.vo.CangKuVo;
import com.zhongyu.vo.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service("CangKuService")
public class CangKuServicelmpl extends ServiceImpl<CangkuMapper, Cangku> implements CangKuService {
@Resource
private  CangkuMapper cangkuMapper;

    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, CangKuVo cangKuVo) {
        LambdaQueryWrapper<Cangku> wrapper= Wrappers.<Cangku>lambdaQuery();
        wrapper.like(!StringUtils.isEmpty(cangKuVo.getName()),Cangku::getCangkuName,cangKuVo.getName())
               .like(!StringUtils.isEmpty(cangKuVo.getAddress()), Cangku::getCangkuAddress, cangKuVo.getAddress())
                .eq(cangKuVo.getUserId()!=null,Cangku::getUserId,cangKuVo.getUserId());
        Page page=new Page(pageNo,pageSize);
        List<Cangku> list=baseMapper.findAll(page,wrapper);
        return new PageResult(list,page.getTotal());
    }

    @Override
    public List<Cangku> searchAll() {
        return cangkuMapper.selectList(null);
    }

    @Override
    public List<Cangku> searchByuserId(Integer userId) {
        return cangkuMapper.findByuserId(userId);
    }

    @Override
    public void add(Cangku cangku) {
        cangkuMapper.insert(cangku);
    }

    @Override
    public void del(Integer id) {
        cangkuMapper.deleteById(id);
    }

    @Override
    public void update(Cangku cangku) {

        cangkuMapper.updateById(cangku);
    }
}
